const addBtn = document.querySelector('#add-btn');
const inputName = document.querySelector('#inputName'),
      inputNum = document.querySelector('#inputNum'),
      inputPrice = document.querySelector('#inputPrice'),
      addFail=document.querySelector('#add-fail');
utils.on(addBtn, 'click', function () {
    const name=inputName.value,
          price=inputPrice.value,
          num=inputNum.value;
     utils.fetch('api/shop/add.php',{name,price,num}).then((resp)=>{
        if(resp.code===200){
            addFail.classList.remove('hide');
            addFail.classList.add('text-success');
            addFail.innerHTML='录入成功';
            setTimeout(()=>{
                $('#addModal').modal('hide')
               getData();
            },1000)
        }else{
            addFail.classList.remove('hide');
            addFail.classList.add('text-danger');
            addFail.innerHTML='网络错误，请重新输入'
            setTimeout(()=>{
                addFail.classList.add('hide');
            },2000)
        }
     })     
})
$('#addModal').on('hidden.bs.modal', function () {
    inputName.value = inputPrice.value = inputNum.value = ''
    addFail.classList.add('hide');
  });